﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BestTrader.Cms.Core.Helper;
using BestTrader.Cms.IServices;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace BestTrader.Cms.Admin.Controllers
{
    public class SetupController : BaseController
    {
        private readonly IBatchService _batchService;
        private readonly IDESEncryptService _desService;
        private readonly ILogger<SetupController> _logger;

        public SetupController(IBatchService batchService, IDESEncryptService desService, ILogger<SetupController> logger) {
            this._batchService = batchService;
            this._desService = desService;
            _logger = logger;
        }

        [HttpGet]
        public IActionResult Init()
        {
            _batchService.RmmfHistoryDealedOrderReportAsync();

            return View();
        }

        [HttpGet]
        public IActionResult Record([FromQuery]DateTime? now)
        {
            _batchService.GetRebateRecordByTime(now);

            return View();
        }

        [HttpGet]
        public IActionResult YunPayOrderSync()
        {
            //_batchService.YunPayOrderSync();

            return View();
        }

        [HttpGet]
        public IActionResult EnManagerSync()
        {
            _batchService.SyncEnManager();

            return Content("OK");
        }

        #region DES

        [HttpGet]
        public IActionResult Des()
        {

            return View();
        }

        [HttpPost]
        public string Des([FromForm]string DesStr)
        {
            var arr = DesStr.Contains(',') ? DesStr.Split(',') : new string[] { DesStr };
            var result = arr.Select(p => _desService.DecryptQQ(p));
            
            return JsonHelper.ObjectToJSON(result);
        }

        #endregion


        [HttpGet]
        public void Logs() {
            _logger.LogInformation("LogInformation GaoTang");
            _logger.LogWarning("LogWarning GaoTang");
            _logger.LogError("LogError GaoTang");
        }
    }
}